package booksys.bob;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

public interface BobDao {
//    @Select("select * from bookborrow where ma_id=#{ma_id}")

    List<Bobcard> findBobcardList(QueryDto queryDto);

    @Select("select lpad(ifnull(max(convert(substring(bob_id,7,3),signed)),0)+1,3,'0')  from bookborrow where bob_id like concat(#{s},'%')")
    String findBobcardNewNum(String s);

    @Insert("insert bookborrow(bob_id,st_id,ma_id,bb_id,bb_btime,bb_extime) values(#{bob_id},#{st_id},#{ma_id},#{bb_id},#{bb_btime},#{bb_extime})")
    void insertBobcard(BobcardDto dto);

    @Select("select count(*) from student where st_id=#{st_id}")
    boolean findstudent(String st_id);

    @Select("select count(*) from bbook where bb_id = #{bb_id}")
    boolean findbook(String bb_id);

    @Select("select bb_state from bbook where bb_id=#{bb_id}")
    boolean findbookbeborrow(String bb_id);

    @Update("update bbook set bb_state = '1' where bb_id in (select bb_id from bookborrow where bob_id=#{bob_id})")
    void updatebb_stateto1(BobcardDto dto);

    @Update("update bookborrow set st_id=#{st_id},bb_id=#{bb_id},bb_retime=#{bb_retime} where bob_id=#{bob_id}")
    void updateBobcard(BobcardDto dto);

    @Select("select bb_id from bookborrow where bob_id=#{bob_id}")
    String getbb_id(String bob_id);

    @Select("select bb_retime from bookborrow where bob_id=#{bob_id}")
    Date getbb_retime(BobcardDto dto);

    @Update("update bbook set bb_state = '0' where bb_id in (select bb_id from bookborrow where bob_id=#{bob_id})")
    void updatebb_stateto0(BobcardDto dto);

    @Delete("delete from bookborrow where bob_id=#{bob_id}")
    void deleteBobcard(String bob_id);
}
